package com.fjh.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjh.domain.PickAddr;
import com.fjh.mapper.PickAddrMapper;
import com.fjh.service.impl.PickAddrService;
import org.springframework.util.StringUtils;

@Service
@Slf4j
public class PickAddrServiceImpl extends ServiceImpl<PickAddrMapper, PickAddr> implements PickAddrService{

    @Autowired
    private PickAddrMapper pickAddrMapper;

    /**
     * 分页查询自提点
     * @param page
     * @param pickAddr
     * @return
     */
    @Override
    public Page<PickAddr> loadPickAddrPage(Page<PickAddr> page, PickAddr pickAddr) {
        return pickAddrMapper.selectPage(page,new LambdaQueryWrapper<PickAddr>()
                            .like(StringUtils.hasText(pickAddr.getAddrName()),PickAddr::getAddrName,pickAddr.getAddrName())
        );
    }

    /**
     * 新增自提点
     * @param pickAddr
     * @return
     */
    @Override
    public boolean save(PickAddr pickAddr) {
        log.info("新增自提点{}", JSON.toJSONString(pickAddr));
        pickAddr.setShopId(1L);
        return super.save(pickAddr);
    }
}
